#!/usr/bin/sh
echo "init frontpanel"
modprobe proton
modprobe simu_button

if [ -e /var/etc/.firstboot ]; then
   echo "WAIT 3 min" > /dev/vfd
   echo "WAIT 3 min"
   rm /var/etc/.firstboot
   touch /dev/.devfsd
fi

if [ -e /etc/init.d/mountvirtfs ]; then
   /etc/init.d/mountvirtfs start
fi
if [ -e /etc/init.d/portmap ]; then
   /etc/init.d/portmap start
fi

modprobe e2_proc

if [ -e /etc/init.d/autofs ]; then
   /etc/init.d/autofs start
fi

if [ ! -e /var/etc/.firstboot ]; then

   echo "Starting DEBUG Interface"
if [ -e /etc/init.d/mountall ]; then
   /etc/init.d/mountall start
fi

   echo "init stmfb"
   modprobe stmcore-display-stx7109c3
   modprobe stmfb display0=1280x720-32@50:12m:pal:yuv:yuv

   echo "LOADING MODULES"
   echo "LOADING" >/dev/vfd

   echo "load a firmware"
   /usr/bin/ustslave /dev/st231-1 /boot/audio.elf
   echo "load v firmware"
   /usr/bin/ustslave /dev/st231-0 /boot/video.elf

   echo "init embx"
   modprobe embxshell
   modprobe embxmailbox mailbox0=0xb9211000:136:set2 mailbox1=0xb9212000:0 ;
   modprobe embxshm mailbox0=shm:0:7:0x60000000:0:256:256:0:1024:0xa4000000:0x10000000 ;
   modprobe mme_host transport0=shm

   echo "init AVS"
   modprobe avs type=stv6418

   player=`cat /proc/stb/player/version`
   player=`cat /proc/stb/player/version | awk '{ print substr( $0, length($0) - 2, length($0) ) }'`
   echo "init player $player"

   modprobe mmelog
   modprobe mpeg2hw mmeName=MPEG2_TRANSFORMER0;
   modprobe ksound
   modprobe p2div64
   modprobe stm_v4l2
   if [ $player -gt 131 ]; then
	modprobe stmvout
	modprobe stmvbi
   fi
   modprobe pseudocard
   
   echo "init frontends"
   modprobe fe-core demod=stb0899 tuner=stb6100 ;

   echo "init drivers"
   modprobe cimax
   modprobe pti

   if [ $player -gt 131 ]; then
	modprobe pti
	modprobe stm_monitor
	modprobe stmsysfs
    	modprobe stmdvb
   else
	modprobe pti
	modprobe stmdvb
	modprobe stm_monitor
   fi	

   modprobe player2
   modprobe sth264pp
   modprobe stmalloc
   modprobe platform
   modprobe smartcard

   showiframe -p /usr/share/bootlogo.mvi &
   stfbcontrol a 0

   echo "init lircd"
   mkdir -p /var/run/lirc
   /usr/bin/lircd

   mknod /dev/rc c 147 1 
   mknod /dev/sci0 c 169 0
   mknod /dev/sci1 c 169 1 
   
   /usr/bin/evremote2 hl101 &

if [ -e /etc/init.d/mountall ]; then
   /etc/init.d/mountall start
fi
if [ -e /etc/init.d/vsftpd ]; then
   /etc/init.d/vsftpd start
fi
   /usr/sbin/inetd

   echo "run app" > /dev/vfd
   echo "LOADING E2"

   until false
   do
      echo "starting e2->"
      /usr/bin/enigma2
      rtv=$?
      echo "e2 ended <- RTV: " $rtv
      case "$rtv" in
		0) echo "0"
		   echo "E2 ERROR"
		   init 6;;
		1) echo "1"
		   echo "SHUTDOWN"
		   init 0;;
		2) echo "2"
		   echo "REBOOT"
		   init 6;;
		3) echo "3"
		   echo "E2 RESTART"
		   echo "0" > /proc/progress
		   showiframe -p /usr/share/bootlogo.mvi &;;
		*) echo "*"
		   echo "ERROR"
		   init 6;;
      esac
   done 
fi
